<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--
    Ignite Spring configuration file to startup grid cache.

    When starting a standalone Ignite node, you need to execute the following command:
    {IGNITE_HOME}/bin/ignite.{bat|sh} path-to-this-file/example-cache.xml

    When starting Ignite from Java IDE, pass path to this file into Ignition:
    Ignition.start("path-to-this-file/example-benchmark.xml");
-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--
        Optional description.
    -->
    <description>
        Spring file for grid configuration with client available endpoints.
    </description>

    <!--
        Initialize property configurer so we can reference environment variables.
    -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_FALLBACK"/>
        <property name="searchSystemEnvironment" value="true"/>
    </bean>

    <!--
        Configuration below demonstrates how to setup a collision and failover SPI's
        to enable work stealing from overloaded nodes to underloaded nodes.

        Note that for job stealing to work, you must always use both,
        GridJobStealingCollisionSpi and GridJobStealingFailoverSPI.
    -->
    <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="igniteInstanceName" value="sslnode"/>

        <!-- Set to local host address. -->
        <property name="localHost" value="127.0.0.1"/>

        <!-- Client configuration. -->
        <property name="connectorConfiguration">
            <bean class="org.apache.ignite.configuration.ConnectorConfiguration">
                <!-- Configure TCP+SSL rest protocol. -->
                <property name="sslEnabled" value="true"/>

                <!-- Sets flag indicating whether or not SSL client authentication is required. -->
                <property name="sslClientAuth" value="true"/>

                <property name="sslFactory">
                    <bean class="org.apache.ignite.ssl.SslContextFactory">
                        <property name="keyStoreFilePath" value="${CLIENTS_MODULE_PATH}/src/test/keystore/server.jks"/>
                        <property name="keyStorePassword" value="123456"/>
                        <property name="trustStoreFilePath" value="${CLIENTS_MODULE_PATH}/src/test/keystore/trust-one.jks"/>
                        <property name="trustStorePassword" value="123456"/>
                    </bean>
                </property>

                <property name="port" value="10443"/>
            </bean>
        </property>

        <property name="cacheConfiguration">
            <!--
                Specify list of cache configurations here. Any property from
                CacheConfiguration interface can be configured here.
            -->
            <list>
                <!--
                    Partitioned cache example configuration.
                -->
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <!-- Cache name is 'partitioned'. -->
                    <property name="name" value="partitioned"/>

                    <!-- PARTITIONED cache mode. -->
                    <property name="cacheMode" value="PARTITIONED"/>

                    <!-- Transactional updates supported. -->
                    <property name="atomicityMode" value="TRANSACTIONAL"/>

                    <!-- Enable near cache to cache recently accessed data. -->
                    <property name="nearConfiguration">
                        <bean class="org.apache.ignite.configuration.NearCacheConfiguration" />
                    </property>

                    <property name="writeSynchronizationMode" value="FULL_SYNC"/>

                    <property name="affinity">
                        <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
                            <constructor-arg value="1"/>
                        </bean>
                    </property>

                    <property name="binaryEnabled" value="true"/>

                    <property name="queryEntities">
                        <list>
                            <bean class="org.apache.ignite.cache.QueryEntity">
                                <property name="valueType" value="GridBinaryPerson"/>
                                <property name="fields">
                                    <map>
                                        <entry key="name" value="java.lang.String"/>
                                        <entry key="address" value="java.lang.String"/>
                                        <entry key="age" value="java.lang.Integer"/>
                                    </map>
                                </property>
                                <property name="indexes">
                                    <list>
                                        <bean class="org.apache.ignite.cache.QueryIndex">
                                            <property name="fields">
                                                <map>
                                                    <entry key="age" value="true"/>
                                                </map>
                                            </property>
                                        </bean>
                                        <bean class="org.apache.ignite.cache.QueryIndex">
                                            <property name="indexType" value="FULLTEXT"/>
                                            <property name="fields">
                                                <map>
                                                    <entry key="address" value="false"/>
                                                </map>
                                            </property>
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                            <bean class="org.apache.ignite.cache.QueryEntity">
                                <property name="valueType" value="GridImplicitBinaryPerson"/>
                                <property name="fields">
                                    <map>
                                        <entry key="name" value="java.lang.String"/>
                                        <entry key="age" value="java.lang.Integer"/>
                                    </map>
                                </property>
                                <property name="indexes">
                                    <list>
                                        <bean class="org.apache.ignite.cache.QueryIndex">
                                            <property name="fields">
                                                <map>
                                                    <entry key="age" value="true"/>
                                                </map>
                                            </property>
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                            <bean class="org.apache.ignite.cache.QueryEntity">
                                <property name="valueType" value="GridNoDefBinaryPerson"/>
                                <property name="fields">
                                    <map>
                                        <entry key="name" value="java.lang.String"/>
                                        <entry key="age" value="java.lang.Integer"/>
                                    </map>
                                </property>
                                <property name="indexes">
                                    <list>
                                        <bean class="org.apache.ignite.cache.QueryIndex">
                                            <property name="fields">
                                                <map>
                                                    <entry key="age" value="true"/>
                                                </map>
                                            </property>
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                        </list>
                    </property>
                </bean>

                <!--
                    Replicated cache example configuration.
                -->
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <!-- Cache name is 'replicated'. -->
                    <property name="name" value="replicated"/>

                    <property name="writeSynchronizationMode" value="FULL_SYNC"/>

                    <property name="atomicityMode" value="TRANSACTIONAL"/>

                    <!-- REPLICATED cache mode. -->
                    <property name="cacheMode" value="REPLICATED"/>
                </bean>

                <!--
                    Replicated cache with in-memory store enabled.
                -->
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <!-- Cache name is 'replicated.store'. -->
                    <property name="name" value="replicated.store"/>

                    <property name="writeSynchronizationMode" value="FULL_SYNC"/>

                    <property name="atomicityMode" value="TRANSACTIONAL"/>

                    <!-- REPLICATED cache mode. -->
                    <property name="cacheMode" value="REPLICATED"/>

                    <!-- Store.-->
                    <property name="store">
                        <bean class="org.apache.ignite.internal.client.HashMapStore"/>
                    </property>
                </bean>
            </list>
        </property>

        <!--
            TCP discovery SPI (uses VM-shared IP-finder).
        -->
        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <!-- Make sure both servers (unsecured and SSL-protected) can start as independent grids. -->
                <property name="localPort" value="48500"/>

                <!-- Override default IP-finder.-->
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <!--
                                    List all IP/port configurations that potentially
                                    can be started first in examples. We are assuming
                                    grid of size 10 or less.
                                -->
                                <value>127.0.0.1:48500</value>
                                <value>127.0.0.1:48501</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>

        <!--
            Logger to use.
        -->
        <property name="gridLogger">
            <bean class="org.apache.ignite.logger.log4j2.Log4J2Logger">
                <constructor-arg type="java.lang.String" value="modules/clients/src/test/resources/log4j2.xml"/>
            </bean>
        </property>

        <!--
            Explicitly set custom public and system thread pools to increase
            possible started nodes count in one VM.
        -->
        <property name="publicThreadPoolSize" value="15"/>

        <property name="systemThreadPoolSize" value="15"/>
    </bean>
</beans>
